﻿using System;
using System.Collections.Generic;
using System.Text;

using CMN.Common;
using CMN.Entity;
using CMN.BLL;
using CMN.Cache;
using System.IO;

namespace CMN.Extends.Job
{
    public  class CreateStaticHtml:IJob
    {
        public void Execute(object executionState)
        {
            //Common.FileTxtLogs.WriteLog(string.Concat(DateTime.Now.ToShortDateString(), "CreateStaticHtml执行生成静态"), false);
            object obj = new object();
           // List<Normal_ChannelEntity> channels = CMNPageHelper.GetChannelListAndAllClassList();
           // Dictionary<string, string> dic = new Dictionary<string, string>();
           // dic.Add("http://www.shbst.net/base/Default.aspx", string.Concat(Utils.GetWebConfigServerPath(), "index.html"));
           // lock (obj)
           // {

           //     for (int i = 0; i < channels.Count; i++)
           //     {

           //         dic.Add("http://www.shbst.net/base/Channels.aspx?ch=" + channels[i].Dir, string.Concat(Utils.GetWebConfigServerPath(), channels[i].Dir, ".html"));
           //         if (!System.IO.Directory.Exists(string.Concat(Utils.GetWebConfigServerPath(), channels[i].Dir + "\\")))
           //         {
           //             System.IO.Directory.CreateDirectory(string.Concat(Utils.GetWebConfigServerPath(), channels[i].Dir + "\\"));
           //         }
           //         foreach (Normal_ClassEntity classEntity in channels[i].ClassEntitys.Values)
           //         {
           //             if (classEntity != null)
           //                 if (classEntity.IsParent)
           //                 {
           //                     dic.Add("http://www.shbst.net/base/Channels.aspx?ch=" + channels[i].Dir + "&cl=" + classEntity.Code, string.Concat(Utils.GetWebConfigServerPath(), channels[i].Dir, "\\_", classEntity.Code, ".html"));

           //                 }
           //                 //else
           //                 //{
           //                 //    dic.Add("http://shbst.net/base/Channel.aspx?ch=" + channels[i].Dir + "&cl=" + classEntity.Code+"&id="+classEntity.Id, string.Concat(Utils.GetWebConfigServerPath(), channels[i].Dir, "\\", classEntity.Code,"_",classEntity.Id ,".html"));
                               
           //                 //}
           //         }
           //     }

           // }
           //// Common.FileTxtLogs.WriteLog(string.Concat(DateTime.Now.ToShortDateString(), "CreateStaticHtml共有静态", dic.Keys.Count.ToString()," 个"), false);
           // string strRequest = string.Empty;
           // foreach (string str in dic.Keys)
           // {
           //    // Common.FileTxtLogs.WriteLog(string.Concat(DateTime.Now.ToShortDateString(), "CreateStaticHtml开始生成静态", str), false);
           //     strRequest = Utils.GetRequestString(str, 16000, 1, Encoding.UTF8);

           //     if (strRequest.Length > 200)
           //     {
           //         Utils.SaveFile(dic[str], strRequest, false, Encoding.GetEncoding("gb2312"));
           //        // Common.FileTxtLogs.WriteLog(string.Concat(DateTime.Now.ToShortDateString(), "CreateStaticHtml生成静态", dic[str]), false);
           //     }
           //     else
           //     {
           //         strRequest = Utils.GetRequestString(str, 16000, 1, Encoding.UTF8);
           //         if (strRequest.Length > 200)
           //         {
                        
           //             Utils.SaveFile(dic[str], strRequest, false, Encoding.GetEncoding("gb2312"));
           //            // Common.FileTxtLogs.WriteLog(string.Concat(DateTime.Now.ToShortDateString(), "CreateStaticHtml生成静态", dic[str]), false);
           //         }
           //     }
               
            //}
           // Common.FileTxtLogs.WriteLog(string.Concat(DateTime.Now.ToShortDateString(), "CreateStaticHtml生成静态成功"), false);
        }
        public void Error(Exception e)
        {
            //Common.FileTxtLogs.WriteLog(string.Concat("生成静态页任务错误:", e.Message, "||", e.Source, "||", e.TargetSite.ToString()),false);
        }
    }
}
